import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache	= $Lazy.file(()=>import('#private/cache-api'))
const $time		= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: '物流人员',			name: 'receiver_id', 				full:true,  required:true, loading:true, type:'select', onValue: ({rows})=>{
				if(rows){
					this.submit = {...this.submit, receiver_name: rows.name}
				}else{
					delete this.submit.receiver_name
				}
			} },
			{ label: '所属标箱',			name: 'box_code', 					full:true, 	disabled:true },
			{ label: '领取时间',			name: 'use_time', 					full:true,  type:'date-time' },
			{ label: '备注',				name: 'content', 					full:true,  type:'textarea' }
		]
	}
	
	model = {}
	
	open = ({ box_code, uuid }) => {
		this.modal.open({ formRef:this.formRef })
		
		this.getModalSelect()
		this.submit = { box_number: uuid }
		
		$time.then(f=>{
			this.formRef.setValue({box_code, use_time: f.getNow() })
		})
	}
	
	// 获取弹框下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, [ 'receiver_id' ], ()=>{
			$cache.then( async f => {
				// 物流人员
				$fn.setRow(formData, 'receiver_id', await f.getCache({ api:'employee'} ) )
				//
				this.setState({ formData })
			})
		})
	}
	
	render(){
		return (
			<>
				{ FormModal.call(this,{ title:'领取', labelWidth:'s5', width:600, api:'box/boxReceive', onRefresh:()=> this.props.onRefresh() }) }
			</>
		)
	}
}

export default Index